<template>
  <el-container class="home-container">
    <el-header>
      <div class="divimg">
        <img class="logoimg" src="~@/assets/logo.png" alt="" />
        <span class="spanimg">人才管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse?'100px':'300px'">
        <div  class="toggle-button" @click="toggle">|||</div>
        <el-menu
          background-color="#3C3C3C"
          text-color="#fff"
          active-text-color="#409EFF"
          unique-opened=""
          :collapse = "isCollapse"
          :collapse-transition="false"
          router
          :default-active="$route.path"
        >
          <el-menu-item :index="'/'+menulist[0].path">
              <i class="el-icon-user"></i>
              <span>{{menulist[0].authName}}</span>
          </el-menu-item>
          <el-menu-item :index="'/'+menulist[1].path">
              <i class="el-icon-document"></i>
              <span>{{menulist[1].authName}}</span>
          </el-menu-item>
          <el-submenu :index="'/'+menulist[2].path">
            <template slot="title">
              <i class="el-icon-user"></i>
              <span>{{menulist[2].authName}}</span>
            </template>
            <el-menu-item :index="'/'+subItem.path" v-for="subItem in menulist[2].children" :key = "subItem.id">
                <!-- 二级菜单模板 -->
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>{{subItem.authName}}</span>
                </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data () {
    return {
      menulist: [
        {
          authName: '添加员工档案',
          id: 125,
          path: 'New',
        },
        {
          authName: '离职办理',
          id: 102,
          path: 'letoff',
        },
        {
          authName: '录入员工信息',
          id: 103,
          path: null,
          children: [
            {
              authName: '每日出勤绩效录入',
              id: null,
              path: 'dailyOperate',
            },
            {
              authName: '荣誉',
              id: null,
              path: 'honor',
            },
            {
              authName: '重大违纪',
              id: null,
              path: 'punish',
            }
          ]
        }
      ],
      iconsObj: {
        '125': 'el-icon-user',
        '103': 'el-icon-set-up',
        '101': 'el-icon-truck',
        '102': 'el-icon-document',
        '145': 'el-icon-s-data'
      },
      isCollapse: true ,
    }
    
  },
  created() {
    //this.getMenuList()
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/Oplogin");
    },
    // async getMenuList() {
    //   const {data:res} = await this.$http.get('menus');
    //   if(res.meta.status!==200) return this.$message.error("请求失败")
    //   this.menulist = res.data;
    // },
    toggle() {
      this.isCollapse = !this.isCollapse;
    }
  },
}
</script>

<style Lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  height: 60px;
  background-color: 	#272727;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: white;
  font-size: 20px;
}

.el-aside {
  background-color:#3C3C3C;
}
.el-aside .el-menu {
  border-right: none;
}
.toggle-button {
  background-color: rgba(124, 122, 122, 0.137);
  font-size: 10px;
  line-height: 24px;
  color: white;
  text-align: center ;
  letter-spacing: 0.2em;
  cursor: pointer;
}
.el-main {
  background-size: 100% 100%;
  /* background-image: url(~@/assets/2.jpg); */
}
.divimg {
  display: flex;
  align-items: center;
}
.spanimg {
  margin-left: 10px;
}
.logoimg {
  height: 40px;
  width: 40px;
  border: 2px solid white;
  background-color: white;
  border-radius: 50%;
}
</style>
